var monitoringConfiguration={
    init:function(){
        var self=this;
        self.shadeDiv = $("#shade-div");
        self.bindEvents();
    },
    bindEvents:function(){
        var self=this;
        $("#addJG").click(function(){
            self.shadeDiv.show();
            $('#JG').setPosition().show();

        })
    $("#btnSvae").click(function(){
          
        var warnlevel=$("#warnlevel").val();
        var warndetail=$("#warndetail").val();
        if(warnlevel==null||warnlevel==""){
        	//alert("告警级别不能为空！");
        	 artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警级别不能",button:[{name: '确定'}]});
        	return false;
        }
        if(warndetail==null||warndetail==""){
        	//alert("级别描述不能为空！");
        	 artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"级别描述不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(isNaN(warnlevel)){
        	//alert("告警级别格式不正确需要数字！");
        	 artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警级别格式不正确需要数字！",button:[{name: '确定'}]});
        	return false;
        }
        
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config!save.xhtml",
    		data : {warnlevel:warnlevel,warndetail:warndetail},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("保存成功！");
    			 artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"保存成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#JG').setPosition().hide();
    			}else{
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    				//alert(data);	
    			}
    		}
    	});
        
     

     })
        
        $(".edit").click(function(){
        	
        	var  warnlevel= $(this).attr("title");
        	//alert(warnlevel);
         	$.ajax({
        		type : "POST",
        		url : "../monitoring/config!mwarnLevelInfo.xhtml",
        		data : {warnlevel:warnlevel},
        		success : function(data) {
        			var obj = eval("("+data+")");
        		    var warnlevel=obj.warnlevel;
        		    var warndetail=obj.warndetail;
        		    $("#UPwarnlevel").val(warnlevel);
        		    $("#UPwarndetail").val(warndetail);
        		}
        	});
        	
            self.shadeDiv.show();
            $('#editJG').setPosition().show();

        })
        
      //修改按钮  
      $("#btnUpdate").click(function(){
          
        var warnlevel=$("#UPwarnlevel").val();
        var warndetail=$("#UPwarndetail").val();
        if(warnlevel==null||warnlevel==""){
        	//alert("告警级别不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警级别不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        if(warndetail==null||warndetail==""){
        	//alert("级别描述不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"级别描述不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(isNaN(warnlevel)){
        	//alert("告警级别格式不正确需要数字！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警级别格式不正确需要数字！",button:[{name: '确定'}]});
        	return false;
        }
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config!update.xhtml",
    		data : {warnlevel:warnlevel,warndetail:warndetail},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("修改成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"修改成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			$('#editJG').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
    

     })
        $("#addRY").click(function(){
            self.shadeDiv.show();
            $('#RY').setPosition().show();

        })
        
      $("#btnSvae1").click(function(){
          
        var warnlevel=$("#warnlevel").val();
        var username=$("#username").val();
        var userphone=$("#userphone").val();
      
        if(warnlevel==null||warnlevel==""){
        	//alert("告警级别不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警级别不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        
        if(username==null||username==""){
        	//alert("名称不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"名称不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(userphone==null||userphone==""){
        	//alert("手机号码不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"手机号码不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(isNaN(userphone)){
        	//alert("手机号码格式不正确！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"手机号码格式不正确！",button:[{name: '确定'}]});
        	return false;
        }
        
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config1!save.xhtml",
    		data : {warnlevel:warnlevel,username:username,userphone:userphone},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("保存成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"保存成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#RY').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
        
     

     })
        
        
        
        
        $(".editRY").click(function(){
        	
        	
        	var  id= $(this).attr("title");
         	$.ajax({
        		type : "POST",
        		url : "../monitoring/config1!info.xhtml",
        		data : {id:id},
        		success : function(data) {
        			var obj = eval("("+data+")");
        		    var warnlevel=obj.warnlevel;
        		    var username=obj.username;
        		    var userphone=obj.userphone;
        		    $("#UPwarnlevel").val(warnlevel);
        		    $("#UPusername").val(username);
        		    $("#UPuserphone").val(userphone);
        		    $("#warnlevelOld").val(id);
        		    
        		}
        	});
        	
        	
            self.shadeDiv.show();
            $('#editRY').setPosition().show();

        })
        
        
     $("#btnUpdate1").click(function(){
        
    	 
    	 
    	 var id=$("#warnlevelOld").val();
        var warnlevel=$("#UPwarnlevel").val();
        var username=$("#UPusername").val();
        var userphone=$("#UPuserphone").val();
      
        if(username==null||username==""){
        	//alert("名称不能为空！");
    		artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"名称不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(userphone==null||userphone==""){
        	//alert("手机号码不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"手机号码不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        if(isNaN(userphone)){
        	//alert("手机号码格式不正确！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"手机号码格式不正确！",button:[{name: '确定'}]});
        	return false;
        }
        //alert(warnlevel);
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config1!update.xhtml",
    		data : {id:id,warnlevel:warnlevel,username:username,userphone:userphone},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("修改成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"修改成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#RY').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
     

     })
        
        
        
        $("#addLX").click(function(){
            self.shadeDiv.show();
            $('#LX').setPosition().show();

        })
        
        
     $("#btnSvae2").click(function(){
          
        var stype=$("#stype").val();
        var sname=$("#sname").val();
        var describe=$("#describe").val();
      
        if(stype==null||stype==""){
        	//alert("监控范围编号不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控范围编号不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        
        if(sname==null||sname==""){
        	//alert("名称不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"名称不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
       
        
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config2!save.xhtml",
    		data : {stype:stype,sname:sname,describe:describe},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("保存成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"保存成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#LX').setPosition().hide();
    			}else{
    				//alert(data);
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
        
     

     })
        
        
        $(".editLX").click(function(){
        	
          	var  id= $(this).attr("title");
         	$.ajax({
        		type : "POST",
        		url : "../monitoring/config2!info.xhtml",
        		data : {id:id},
        		success : function(data) {
        			var obj = eval("("+data+")");
        		    var stype=obj.stype;
        		    var sname=obj.sname;
        		    var describe=obj.describe;
        		    $("#UPstype").val(stype);
        		    $("#UPsname").val(sname);
        		    $("#UPdescribe").val(describe);
        		    $("#sld").val(id);
        		    
        		}
        	});
        	
            self.shadeDiv.show();
            $('#editLX').setPosition().show();

        })
        
        
   $("#btnUpdate2").click(function(){
    	 
    	 var id=$("#sld").val();
    	 var stype=$("#UPstype").val();
         var sname=$("#UPsname").val();
         var describe=$("#UPdescribe").val();
      
         if(stype==null||stype==""){
         	//alert("监控范围编号不能为空！");
         	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控范围编号不能为空！",button:[{name: '确定'}]});
         	return false;
         }
         
         
         if(sname==null||sname==""){
         	//alert("名称不能为空！");
         	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"名称不能为空！",button:[{name: '确定'}]});
         	return false;
         }
        //alert(warnlevel);
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config2!update.xhtml",
    		data : {id:id,stype:stype,sname:sname,describe:describe},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("修改成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"修改成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('editLX.').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
     

     })
     
     
        
        $("#addDX").click(function(){
            self.shadeDiv.show();
            $('#saveDX').setPosition().show();

        })
        
        
     $("#btnSvae3").click(function(){
          
        var targetid=$("#targetid").val();
        var pid=$("#pid").val();
        var pids=pid.split("_");
        var sid=$("#sid").val();
        var sids=sid.split("_");
        var sdetail=$("#sdetail").val();
        var warnlevelId=$("#warnlevelId").val();
        var warnthreshold=$("#warnthreshold").val();
        
      
        if(targetid==null||targetid==""){
        	//alert("监控对象编码不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控对象编码不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        
        if(sdetail==null||sdetail==""){
        	//alert("监控范围明细不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控范围明细不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        if(warnthreshold==null||warnthreshold==""){
        	//alert("告警阀值不能为空！");
           artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警阀值不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
       
        
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config3!save.xhtml",
    	data : {targetid:targetid,sdetail:sdetail,warnlevel:warnlevelId,warnthreshold:warnthreshold,netid:pids[0],pname:pids[2],ip:pids[1],stype:sids[0],sname:sids[1]},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("保存成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"保存成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#saveDX').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});

     })
     
     
            $(".editDX").click(function(){
        	
          	var  id= $(this).attr("title");
         	$.ajax({
        		type : "POST",
        		url : "../monitoring/config3!info.xhtml",
        		data : {id:id},
        		success : function(data) {
        			var obj = eval("("+data+")");
        		    var targetid=obj.targetid;
        		    var netid=obj.netid;
        		    var ip=obj.ip;
        		    var pname=obj.pname;
        		    var stype=obj.stype;
        		    var sdetail=obj.sdetail;
        		    var warnthreshold=obj.warnthreshold;
        		    var warnlevel=obj.warnlevel;
        		    
        		    $("#UPtargetid").val(targetid);
        		    $("#UPpid").val(netid+"_"+ip+"_"+pname);
        		   // alert( $("#UPpid").val());
        		    $("#UPsid").val(stype);
        		    $("#UPsdetail").val(sdetail);
        		    $("#UPwarnthreshold").val(warnthreshold);
        		    $("#UPwarnlevelId").val(warnlevel);
        		    $("#sld").val(id);
        		    
        		}
        	});
        	
            self.shadeDiv.show();
            $('#editDX').setPosition().show();

        })  
        
        
      $("#btnUpdate3").click(function(){
    	  
        var targetid=$("#UPtargetid").val();
       // var pid=$("#UPpid").attr("title");
        var pid= $("#UPpid").find("option:selected").attr("title");
        var pids=pid.split("_");
       // var sid=$("#UPsid").attr("title");
        var sid=$("#UPsid").find("option:selected").attr("title");
        var sids=sid.split("_");
        var sdetail=$("#UPsdetail").val();
        var warnlevelId=$("#UPwarnlevelId").val();
        var warnthreshold=$("#UPwarnthreshold").val();
        var id=$("#sld").val();
      
        if(targetid==null||targetid==""){
        	//alert("监控对象编码不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控对象编码不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
        
        if(sdetail==null||sdetail==""){
        	//alert("监控范围明细不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"监控范围明细不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        if(warnthreshold==null||warnthreshold==""){
        	//alert("告警阀值不能为空！");
        	artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"告警阀值不能为空！",button:[{name: '确定'}]});
        	return false;
        }
        
  
        
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config3!update.xhtml",
    	data : {id:id,targetid:targetid,sdetail:sdetail,warnlevel:warnlevelId,warnthreshold:warnthreshold,netid:pids[0],pname:pids[2],ip:pids[1],stype:sids[0],sname:sids[1]},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("修改成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"修改成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			  $('#editDX').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});

     })
       
        $(".del").click(function(){
        	var  warnlevel= $(this).attr("title");
        	$("#deId").val(warnlevel);
            self.shadeDiv.show();
            $('#warning').setPosition().show().find("p.center").html("确定要删除吗？");

        })
      //删除按钮  
      $("#btnDelete").click(function(){
          
    	var deId=  $("#deId").val();
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config!delete.xhtml",
    		data : {warnlevel:deId},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("删除成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"删除成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			$('.del').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
    

     })
     
         //删除按钮 1 
      $("#btnDelete1").click(function(){
          
    	var deId=  $("#deId").val();
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config1!delete.xhtml",
    		data : {id:deId},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("删除成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"删除成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			$('.del').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
    

     })
     
     
           //删除按钮 2 
      $("#btnDelete2").click(function(){
          
    	var deId=  $("#deId").val();
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config2!delete.xhtml",
    		data : {id:deId},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("删除成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"删除成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			$('.del').setPosition().hide();
    			}else{
    				//alert(data);
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
    

     })
     
          
           //删除按钮 3 
      $("#btnDelete3").click(function(){
          
    	var deId=  $("#deId").val();
    	$.ajax({
    		type : "POST",
    		url : "../monitoring/config3!delete.xhtml",
    		data : {id:deId},
    		success : function(data) {
    			 self.shadeDiv.hide();
    			if(data=='true'){
    			//alert("删除成功！");
    			artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"删除成功！",button:[{name: '确定'}]});
    			common.refreshPage();
    			$('.del').setPosition().hide();
    			}else{
    				//alert(data);	
    				artDialog({icon: 'warning',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:data,button:[{name: '确定'}]});
    			}
    		}
    	});
    

     })

    },
    ajaxGET:function (url, data, fn,beforeSendFn) {
        var beforeSendFn = beforeSendFn || function(){};
        $.ajax({type:"GET", dataType:'json', context:this, url:url, data:data, success:fn, beforeSend:beforeSendFn});
    },
    ajaxPOST:function (url, data, fn,beforeSendFn) {
        var beforeSendFn = beforeSendFn || function(){};
        $.ajax({type:"POST", dataType:'json', context:this, url:url, data:data, success:fn, beforeSend:beforeSendFn});
    }
}
$(function(){
    monitoringConfiguration.init()
})


var zid="";
var ztype="";
function qy(id,type){
	zid=id;
	ztype=type;
	if(type==1){
	 $('#warning3').setPosition().show().find("p.center").html("确定要启用当前用户？");
	}else if(type==0){
	  $('#warning3').setPosition().show().find("p.center").html("确定要禁用当前用户？");
	}

	
}

function qyok(){
	
	 $('#warning3').setPosition().hide();
	$.ajax({
		type : "POST",
		url : "../monitoring/config3!updateState.xhtml",
		data : "id="+zid+"&utype="+ztype,
		beforeSend : function() {
		},
		success : function(data) {
			
		    // $('#warning').setPosition().show().find("p.center").html(data);
			if(ztype==1){
				//alert("启用成功");
				artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"启用成功",button:[{name: '确定'}]});
				$("#ss"+zid).html("已启动监控");
				$("#ss"+zid).attr("href","javascript:qy("+zid+",0)");
				
			}else if(ztype==0){
				//alert("禁用成功");
				artDialog({icon: 'succeed',title: '提示',lock: true,opacity: 0.2,zIndex:8888,content:"禁用成功",button:[{name: '确定'}]});
				$("#ss"+zid).html("已禁用监控");
				$("#ss"+zid).attr("href","javascript:qy("+zid+",1)");
			}
		}
	});
	
	
}
